﻿using System;
using System.Web.Services;
using OrderManage.BLL;
using OrderManage.Model;
using OrderManage.Utility;

namespace OrderManage.WebApp.Service
{
    /// <summary>
    /// OrderWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class OrderWebService : WebService
    {
        public ServiceSoapHeader SoapHeader = new ServiceSoapHeader();
        private readonly OrderBLL _bll = new OrderBLL();


        /// <summary>
        /// 修改错误代码和错误表述
        /// </summary>
        /// <returns></returns>
        [WebMethod(Description = "修改错误代码和错误表述,orderId:订单编号,status:状态,errorCode:错误代码,errorText:错误表述")]
        [System.Web.Services.Protocols.SoapHeader("SoapHeader")]
        public bool ModifyErrorCodeAndText(int orderId, int status, int errorCode, string errorText)
        {
            var result = false;
            if (SoapHeader.UserName.Equals("root"))
            {
                result = _bll.ModifyErrorCodeAndText(orderId, status, errorCode, errorText);
            }
            return result;
        }

        /// <summary>
        /// 删除某一个订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [WebMethod(Description = "删除某一个订单,orderId:订单编号")]
        [System.Web.Services.Protocols.SoapHeader("SoapHeader")]
        public bool RemoveOrder(int orderId)
        {
            var result = false;
            if (SoapHeader.UserName.Equals("root"))
            {
                result = _bll.RemoveOrder(orderId);
            }
            return result;
        }

        /// <summary>
        /// 获取所有失败订单
        /// </summary>
        /// <returns></returns>
        [WebMethod(Description = "获取所有失败订单,status:订单状态")]
        [System.Web.Services.Protocols.SoapHeader("SoapHeader")]
        public OrderEntity[] GetOrders(int status)
        {
            OrderEntity[] orderArray = null;
            if (SoapHeader.UserName.Equals("root"))
            {
                orderArray = _bll.GetOrders(status).ToArray();
            }
            return orderArray;
        }
        /// <summary>
        /// 获取订单
        /// </summary>
        /// <param name="status">状态</param>
        /// <param name="count">数量</param>
        /// <returns></returns>
        [WebMethod(Description = "获取订单,status:订单状态,count:数量")]
        [System.Web.Services.Protocols.SoapHeader("SoapHeader")]
        public OrderEntity[] GetOrder(int status, int count)
        {
            OrderEntity[] orderArray = null;
            if (SoapHeader.UserName.Equals("root"))
            {
                orderArray = _bll.GetOrder(status, count).ToArray();
            }
            return orderArray;
        }

        /// <summary>
        /// 获取订单数量
        /// </summary>
        /// <param name="status">状态</param>
        /// <returns></returns>
        [WebMethod(Description = "获取订单数量,status:订单状态")]
        [System.Web.Services.Protocols.SoapHeader("SoapHeader")]
        public int GetOrderCount(int status)
        {
            int result = 0;
            if (SoapHeader.UserName.Equals("root"))
            {
                result = _bll.GetOrderCount(status);
            }
            return result;
        }
    }
}
